<?php
/*
 * Clase personalizada de enrutamiento.
 *
 * Basado en la información encontrada en:
 * http://www.symfony-project.org/more-with-symfony/1_4/es/02-Advanced-Routing
*/

class renderSectionObjectRoute extends sfDoctrineRoute
{
    protected $portal;

    public function matchesUrl($url, $context = array())
    {
        if (false === $parameters = parent::matchesUrl($url, $context))
        {
            return false;
        }

        $portalSlug = $parameters['portal_slug'];

        $portal = Doctrine_Core::getTable('EmsPortal')->findOneBySlug($portalSlug);

        if (!$portal)
        {
            return false;
        }

        $this->portal = $portal;

        return array_merge(array('portal_id' => $portal->id), $parameters);
    }

    protected function getRealVariables()
    {
        return array_merge(array('portal_id'), parent::getRealVariables());
    }

    protected function doConvertObjectToArray($object)
    {
        $parameters = parent::doConvertObjectToArray($object);

        unset($parameters['portal_id']);

        return $parameters;
    }

    public function getPortal()
    {
        return $this->portal;
    }
}